﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;

namespace IHISCETeim.Web.MachineSys.FTradeModel
{
    public partial class FTradeAgeDetaiHistory : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "FTradeReceivablesListEasyUI";
            }
        }
        /// <summary>
        /// 不用权限
        /// </summary>
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.none };
            }
        }
        

        protected int FTradeSalesId
        {
            get
            {
                return GetRequestValue<int>("FTradeSalesId", 0);
            }
        }
        protected int FTradeAgeId
        {
            get
            {
                return GetRequestValue<int>("FTradeAgeId", 0);
            }
        }

        private FTradeSalesTypeInfo _objFx = null;

        protected FTradeSalesTypeInfo obj
        {
            get
            {
                if (_objFx == null)
                    _objFx = FTradeSalesTypeController.GetByFTradeSalesId(FTradeSalesId);
                return _objFx;
            }
        }



        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected string GetShowHtml()
        {
            List<FTradeAgeDetailInfo> alllist = FTradeAgeDetailController.GetAllByFTradeSalesId(FTradeSalesId);
            FTradeAgeDetailInfo tempObj=new FTradeAgeDetailInfo(); 
            List<FTradeAgeDetailInfo> list=new List<FTradeAgeDetailInfo>();
           
            int suspendedmark=FTradeAgeId;
            while(suspendedmark>0)
            {
                tempObj= alllist.Single(e => e.FTradeAgeId == suspendedmark);
                list.Add(tempObj);
                suspendedmark=tempObj.SuspendedMark;
            }

            StringBuilder sb = new StringBuilder();

            string htmltemp="<div style=\"clear:both;border:1px dotted #B8D0D6; margin:5px 0px; line-height:25px; \">"+
                            "<table>"+
                            "    <tr >"+
                            "        <td width=\"50px\"><img src=\"themes/css/ihisceImg/{0}.png\" /></td>"+
                            "        <td width=\"90px\" style=\"line-height:25px;\">{1} 于</td>"+
                            "        <td width=\"120px\" style=\"line-height:25px;\">{2}</td>"+
                            "        <td width=\"120px\" style=\"line-height:25px; \">{3} {4} 万元</td>"+
                            "        <td width=\"120px\" style=\"line-height:25px; \">于 {5}　到期</td>"+
                            "    </tr>"+
                            "</table>"+
                            "</div>";

            FTradeAgeDetailInfo firstObj = list.FirstOrDefault(e => e.SuspendedMark == 0);//第一次添加的记录
            FTradeAgeDetailInfo lastObj = list.FirstOrDefault(e => e.SuspendedMark > 0 && e.State == "正常" || e.State == "已冲帐");
            List<FTradeAgeDetailInfo> histryList = list.FindAll(e => e.SuspendedMark > 0 && e.State == "缓期") ;

            if (firstObj != null)
            {
                sb.AppendFormat(htmltemp,"pen",firstObj.RealName,Convert.ToDateTime(firstObj.CreateDate).ToString("yyyy-MM-dd")+"　添加了 ",firstObj.ShowTitle,firstObj.JinE,firstObj.DaoQiRi.ToShortDateString());
            }

            if (histryList != null)
            {
                foreach (var itm in histryList)
                {
                    sb.AppendFormat(htmltemp, "arrow2-down", itm.RealName, Convert.ToDateTime(itm.CreateDate).ToString("yyyy-MM-dd") + "　<b>缓期了<b> ", itm.ShowTitle, itm.JinE, itm.DaoQiRi.ToShortDateString());
                }
            }
            if (lastObj != null)
            {
                sb.AppendFormat(htmltemp, "arrow2-right", lastObj.RealName, Convert.ToDateTime(lastObj.CreateDate).ToString("yyyy-MM-dd") + "　<b>缓期了<b/> ", lastObj.ShowTitle, lastObj.JinE, lastObj.DaoQiRi.ToShortDateString());
            }

            return sb.ToString() ;
        }
    }
}